package com.yjc.dp;

/**
 * 53. 最大子数组和
 *
 * @author yjc
 * @create 2024-08-09 17:07
 */
public class Subject_15 {
    public static void main(String[] args) {
        int[] nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4};

        int n = nums.length;
        int[] dp = new int[n + 1];

        for (int i = 0; i < n; i++) {
            dp[i] = nums[i];
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                dp[i] = Integer.max(dp[i], dp[j] + nums[j]);
            }
        }
        System.out.println(dp[n-1]);
    }
}
